<!doctype html>
<html lang="en">
    <head>
        <title>LOGIN</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="bootstrap.min.css">

        <!-- Custom Styles -->
        <link rel="stylesheet" type="text/css" href="./styles.css">

        <script src="jquery-3.6.0.min.js"></script>
    </head>

    <body>

        <!-- Backgrounds -->

        <div id="login-bg" class="container-fluid">

            <div class="bg-img"></div>
            <div class="bg-color"></div>
        </div>

        <!-- End Backgrounds -->

        <div class="container" id="login">
            <div class="row justify-content-center">
                <div class="col-lg-8">
                    <div class="login">

                        <h1>Login</h1>
                        <form>
                            <div class="form-group">
                                <input type="text" class="form-control" name="username" required
                                       aria-describedby="emailHelp" placeholder="username">

                            </div>
                            <div class="form-group">
                                <input type="password" class="form-control" name="password" required
                                       placeholder="Password">
                            </div>
                            <br>
                            <button type="button" class="btn btn-lg btn-block btn-success" onclick="submitForm()">Sign
                                in
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script type="text/javascript">
        var submitForm = function () {
            var postData = {};
            var username = $("input[name='username']").val()
            var password = $("input[name='password']").val()
            postData.username = username;
            postData.password = password;
            $.ajax({
                type: "POST",
                url: "/view/docs/login",
                data: postData,
                dataType: "json"
            }).done(function (rs) {
                alert(1)
                console.log(rs)
                window.location.url = '/docs/index.html'
            }).fail(function (request) {
                if (request.status == 401) {
                    alert("登录失败")
                }
                if(request.status == 200){
                    $(location).attr('href','/docs/index.html')
                }
                console.log(request)
            })
        };
    </script>

</html>